<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('单词信息管理列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
         <div class="row">
             <div class="col-sm-12 search-collapse">
                 <form id="formId">
                     <div class="select-list">
                         <!-- 第一行：常规搜索条件 -->
                         <div class="row">
                             <div class="col-md-3">
                                 <label>单词外文：</label>
                                 <input type="text" name="name" class="form-control"/>
                             </div>
                             <div class="col-md-3">
                                 <label>中文翻译：</label>
                                 <input type="text" name="meaning" class="form-control"/>
                             </div>
                             <div class="col-md-3">
                                 <label>可用状态：</label>
                                 <select name="status" class="form-control" th:with="type=${@dict.getType('word_status')}">
                                     <option value="">所有</option>
                                     <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                 </select>
                             </div>
                             <div class="col-md-3">
                                 <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                 <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                             </div>
                         </div>

                         <!-- 第二行：单词分组信息标签 -->
                         <div class="row mt-3">
                             <div class="col-12">
                                 <label class="is-required">单词分组信息</label>
                             </div>
                         </div>

                         <!-- 第三行：复选框分组，每行三个 -->
                         <div class="row mt-2">
                             <div class="col-12">
                                 <div class="checkbox-group border p-3 rounded">
                                     <div th:with="wordTypes=${@wordDict.getType()}" class="form-group">
                                         <div class="row">
                                             <div th:each="wordDict,iter : ${wordTypes}" class="col-md-4 mb-2">
                                                 <div class="form-check">
                                                     <input type="checkbox"
                                                            th:id="'group-' + ${wordDict.id}"
                                                            th:value="${wordDict.id}"
                                                            name="groupIds"
                                                            class="form-check-input">
                                                     <label class="form-check-label"
                                                            th:for="'group-' + ${wordDict.id}"
                                                            th:text="${wordDict.value}"></label>
                                                 </div>
                                             </div>
                                         </div>
                                     </div>
                                 </div>
                             </div>
                         </div>
                     </div>
                 </form>
             </div>

             <div class="btn-group-sm" id="toolbar" role="group">
                 <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="teacher:wordinfo:add">
                     <i class="fa fa-plus"></i> 添加
                 </a>
                 <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="teacher:wordinfo:export">
                     <i class="fa fa-download"></i> 导出
                 </a>
             </div>
             <div class="col-sm-12 select-table table-striped">
                 <table id="bootstrap-table"></table>
             </div>
         </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('teacher:wordinfo:edit')}]];
        var removeFlag = [[${@permission.hasPermi('teacher:wordinfo:remove')}]];
        var statusDatas = [[${@dict.getType('word_status')}]];
        var prefix = ctx + "teacher/wordinfo";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "单词信息管理",
                columns: [
                {
                    field: 'id',
                    title: '主键',
                    visible: false
                },
                {
                    field: 'name',
                    title: '单词外文'
                },
                {
                    field: 'meaning',
                    title: '中文翻译'
                },
                {
                    field: 'etymology',
                    title: '词源'
                },
                {
                    field: 'partOfSpeech',
                    title: '词性'
                },
                {
                    field: 'image',
                    title: '图片',
                    formatter: function(value, row, index) {
                        return value ? '<img src="' + value + '" style="width:50px; height:auto;">' : '暂无图片';
                    }
                },
                {
                    field: 'sound',
                    title: '语音',
                    formatter: function(value, row, index) {
                        return value ? `
                            <audio id="audio-${row.id}" src="${value}" preload="none"></audio>
                            <button class="btn btn-primary btn-xs" onclick="document.getElementById('audio-${row.id}').play()">
                                <i class="fa fa-play"></i> 播放
                            </button>
                        ` : '暂无语音';
                    }
                },
                {
                    field: 'status',
                    title: '可用状态',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(statusDatas, value);
                    }
                },
                {
                    field: 'updateTime',
                    title: '更新时间'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
            
            // 全选功能
            $('#checkAll').on('click', function() {
                $('.group-checkbox').prop('checked', this.checked);
            });
            
            // 分组复选框点击时更新全选状态
            $('.group-checkbox').on('click', function() {
                $('#checkAll').prop('checked', 
                    $('.group-checkbox').length === $('.group-checkbox:checked').length);
            });
        });
    </script>
</body>
</html>